charset="UTF-8"
Ext.onReady(function(){
	Ext.QuickTips.init();
     // example of custom renderer function
    function change(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '</span>';
        }
        return val;
    }

    // example of custom renderer function
    function pctChange(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '%</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '%</span>';
        }
        return val;
    }

        
	var medicineRecord = Ext.data.Record.create([
				{name:'id'},  
              {name:'name'},  
              {name:'unit'},  
              {name:'size'}
		]);
     // create the data store
    var medicineStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"queryMedicineByPageDoctor.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'medicineVOList'
        	 }, 
        	 medicineRecord
        	 )
    });
medicineStore.load({params:{start:0,limit:5}});


	 var medicineSM = new Ext.grid.CheckboxSelectionModel();  
	 
    var medicineColumn = new Ext.grid.ColumnModel({
    		columns:[
    		new Ext.grid.RowNumberer(),
    		medicineSM,
            {
            	header: "药品编号", 
            	width: 70, 
            	sortable: true, 
            	dataIndex: 'id'
            },
            {
            	header: "名称", 
            	width: 150,
            	sortable: true,
            	dataIndex: 'name'
            },
            {
            	header: "单位", 
            	width: 100,
            	sortable: true,
            	dataIndex: 'unit'
            },
            {
            	header: "规格", 
            	width: 100,
            	dataIndex: 'size'
            }
        ]});
        medicineColumn.defaultSortable = true;//默认可排序  

        

  
    
     //修改就诊记录面板
    var updateDiagnoseForm = new Ext.FormPanel({
        labelAlign: 'top',
        frame:true,
        title: '就诊信息',
        bodyStyle:'padding:5px 5px 0',
        width: 600,
        items:[
        	{layout:'column',border:false,labelSeparator:':',
             defaults:{layout: 'form',border:false,columnWidth:.25},
              items:[
               		
                    {items: [{
                    	xtype:'textfield',
                    	disabled:true,
                    	fieldLabel: '身份证号码',
                    	id:'patientIdentify',
                    	name: 'identify',
                    	anchor:'90%'
                    	}]},
                    {items: [{
						xtype:'textfield',
						disabled:true,
                    	fieldLabel: '姓名',
                    	id:'patientName',
                    	name: 'name',
                    	anchor:'90%'
                    	}]},
                    {items: [{
                    	xtype:'numberfield',
                    	id:'id',
                    	name: 'id',
                    	hidden:true,
                    	anchor:'90%'
                    	}]},
                	{items: [{
                    	xtype:'numberfield',
                    	id:'medicineId',
                    	name: 'medicineId',
                    	hidden:true,
                    	anchor:'90%'
                    	}]},
                    {columnWidth:1.0,items: [{
                			xtype:'htmleditor',
                    		allowBlank:false,
                    		blankText:'不能为空',
                    		maxLength:1000,
                    		maxLengthText:'最大长度1000',
                    		fieldLabel: '病情描述',
                    		id: 'descripition',
                    		name: 'descripition',
                    		height:100,
                    		anchor:'90%'
                    }]},
                    {columnWidth:1.0,items: [{
                			xtype:'htmleditor',
                    		allowBlank:false,
                    		blankText:'不能为空',
                    		maxLength:1000,
                    		maxLengthText:'最大长度1000',
                    		fieldLabel: '诊断结果',
                    		id: 'result',
                    		name: 'result',
                    		height:100,
                    		anchor:'90%'
                    }]},
					 {items: [{
						xtype:'textfield',
						allowBlank:false,
                    	blankText:'不能为空',
                    	maxLength:50,
                    	maxLengthText:'最大长度50',
                    	fieldLabel: '给药方式',
                    	id:'way',
                    	name: 'way',
                    	anchor:'90%'
                    	}]},
                    {items: [{
						xtype:'textfield',
						allowBlank:false,
                    	blankText:'不能为空',
                    	maxLength:50,
                    	maxLengthText:'最大长度50',
                    	fieldLabel: '一次用量',
                    	id:'onetime',
                    	name: 'onetime',
                    	anchor:'90%'
                    	}]},
                    {
                    columnWidth:1.0,
                    items: [{
						xtype:"grid",
						store : medicineStore,  
                        cm : medicineColumn,  
                        sm : medicineSM,  
                        id : 'medicineGrid', 
                        name:'medicineGrid',
                        title : '药品列表',  
                        viewConfig: {
            				forceFit:true//加入该选项全屏显示表格且自适应大小，不产生横向滚动条
         				},
                        height : 170 ,
                        anchor:'90%',
                         bbar: new Ext.PagingToolbar({
            			pageSize: 5,
            			store: medicineStore,
           				displayInfo: true,
						displayMsg:'显示第 {0} 条到 {1} 条记录，一共 {2} 条',  
            			emptyMsg:'没有记录',
            			plugins: new Ext.ux.ProgressBarPager()
        				})
                        
					}]}
                   
               ]}
               ],
		monitorValid:true,
		
        buttons: [{
            text: '保存',
            formBind: true,
            handler:function(){     
            	if(medicineSM.getCount() != 1){
            		 Ext.MessageBox.alert('错误', '请选择药品');
            	}
            	else{
            		var s = medicineSM.getSelected();
            	updateDiagnoseForm.getForm().findField('medicineId').setValue(s.get('id'));
            	Ext.Ajax.request({
     							 url:'updateDiagnoseDoctor.action',      
                     				method:'post',               
        						success:function(form,action){                   //发送成功的回调函数
       								Ext.Msg.alert('信息','修改成功');        //弹出对话框
       								updateDiagnoseWindow.hide();
       								diagnoseStore.reload();
      							},
     							failure:function(form,action){                          //发送失败的回调函数
       								Ext.Msg.alert("错误", "修改失败");
      							},
     							params:{
     								medicineId : updateDiagnoseForm.getForm().findField('medicineId').getValue(),
     								id : updateDiagnoseForm.getForm().findField('id').getValue(),
     								descripition : updateDiagnoseForm.getForm().findField('descripition').getValue(),
     								result : updateDiagnoseForm.getForm().findField('result').getValue(),
     								way : updateDiagnoseForm.getForm().findField('way').getValue(),
     								onetime: updateDiagnoseForm.getForm().findField('onetime').getValue()
     								} //发送参数
    						});

            	}
            	
                 
                }
        },{
            text: '取消',
            handler:function(){
					updateDiagnoseForm.form.reset();
                    updateDiagnoseWindow.hide();
                }
        }]
    });
	//修改就诊记录窗体
    var updateDiagnoseWindow = new Ext.Window({
	title : '修改就诊记录',
	width : 615,
	height : 670,
	plain : true,
	closeAction : 'hide',// 关闭窗口
	maximizable : false,// 最大化控制 值为true时可以最大化窗体
	layout:'Form',
	items : [updateDiagnoseForm]
});





    //查询诊断面板
    var queryDiagnoseForm = new Ext.FormPanel({
        labelAlign: 'top',
        frame:true,
        title: '查询条件',
        bodyStyle:'padding:5px 5px 0',
        width:780,
        collapsible: true,//最小化
        items:[
        	{layout:'column',border:false,labelSeparator:':',
             defaults:{layout: 'form',border:false,columnWidth:.25},
              items:[
                    
                   {items: [{
							xtype:'datefield',
                    		fieldLabel: '预约日期',
                    		id:'querysignday',
                    		name: 'signday',
                    		emptyText:'请选择日期', 
                    		invalidText : "{0} 是无效的日期 - 必须符合格式： {1}", 
                    		minValue:new Date(new Date().getDate()-1),  
          					minText:'时间不能超过今天',  
							format : "Y-m-d" , 
          					showToday:false,
                    		anchor:'90%'
                    }]}
               ]}
               ],
		monitorValid:true,
		
        buttons: [{
            text: '查询',
            formBind: true,
            handler:function(){       
            	diagnoseStore.baseParams = {
                	signday:queryDiagnoseForm.getForm().findField('signday').getValue()
        		},
                diagnoseStore.reload({params:{start:0,limit:15}});
                }
        },{
            text: '重置',
            handler:function(){
					queryDiagnoseForm.form.reset();
					queryDiagnoseForm.getForm().findField('doctorId').setDisabled(true);
					queryDiagnoseForm.getForm().findField('departmentId').setDisabled(true);
					diagnoseStore.removeAll();
                }
        }]
    });
    

    
	
  
var diagnoseRecord = Ext.data.Record.create([
				{name:'id'},  
              {name:'patientIdentify'},  
              {name:'patientName'},  
              {name:'time'}, 
              {name:'workdate',type : 'date', dateFormat : 'Y-m-d'},
           //   {name:'state'},
              {name:'descripition'},
               {name:'result'},
               {name:'medecineName'},
               {name:'medecineWay'},
               {name:'medecineOnetime'}
		]);
    // create the data store
    var diagnoseStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"querySignByPageDoctor.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'diagnoseVOList'
        	 }, 
        	 diagnoseRecord
        	 )
    });

	 var sm = new Ext.grid.CheckboxSelectionModel();  
	 
    var column = new Ext.grid.ColumnModel({
    		columns:[
    		new Ext.grid.RowNumberer(),
    		sm,
            {
            	header: "预约编号", 
            	width: 70, 
            	sortable: true, 
            	dataIndex: 'id'
            },
            {
            	header: "预约日期", 
            	width: 120,
            	sortable: true,
            	renderer: Ext.util.Format.dateRenderer('Y/m/d'), 
            	dataIndex: 'workdate'
            },
            {
            	header: "预约时间", 
            	width: 80,
            	sortable: true,
            	dataIndex: 'time'
            },
            {
            	header: "患者身份证", 
            	width: 150,
            	dataIndex: 'patientIdentify'
            },
            {
            	header: "患者姓名", 
            	width: 100,
            	dataIndex: 'patientName'
            }/*,
            {
            	header: "预约状态", 
            	width: 80,
            	sortable: true,
            	dataIndex: 'state'
            }*/,
            {
            	header: "病情描述", 
            	width: 100,
            	dataIndex: 'descripition'
            },
            {
            	header: "诊断结果", 
            	width: 100,
            	dataIndex: 'result'
            },
            {
            	header: "药品名称", 
            	width: 100,
            	dataIndex: 'medecineName'
            },
            {
            	header: "给药方式", 
            	width: 100,
            	dataIndex: 'medecineWay'
            },
            {
            	header: "一次用量", 
            	width: 100,
            	dataIndex: 'medecineOnetime'
            }
        ]});
        column.defaultSortable = true;//默认可排序  


        
    // create the Grid
    var diagnoseGrid = new Ext.grid.GridPanel({
        id:'diagnose-grid',
        store: diagnoseStore,
        cm: column,
        sm: sm,
        height:400,
        width:780,
        title:'诊断信息列表',
		loadMask: {msg:'正在加载数据，请稍侯……'},
		collapsible: true,//最小化
        plugins: new Ext.ux.PanelResizer({
            minHeight: 100
        }),
        tbar: [{
        	ref: '../updateBtn',
            iconCls: 'icon-update',
            text: '修改病历',
            disabled: true,
            handler: function(){
            	var s = diagnoseGrid.getSelectionModel().getSelected();
            	updateDiagnoseForm.getForm().findField('id').setValue(s.get('id'));
            	updateDiagnoseForm.getForm().findField('patientIdentify').setValue(s.get('patientIdentify'));
            	updateDiagnoseForm.getForm().findField('patientName').setValue(s.get('patientName'));
            	updateDiagnoseForm.getForm().findField('descripition').setValue(s.get('descripition'));
            	updateDiagnoseForm.getForm().findField('result').setValue(s.get('result'));
            	updateDiagnoseWindow.show();
            }
        }],
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: diagnoseStore,
            displayInfo: true,
			displayMsg:'显示第 {0} 条到 {1} 条记录，一共 {2} 条',  
            emptyMsg:'没有记录',
            plugins: new Ext.ux.ProgressBarPager()
        })
    });

    diagnoseGrid.getSelectionModel().on('selectionchange', function(sm){
       
        diagnoseGrid.updateBtn.setDisabled(sm.getCount() != 1);
        
    });

   diagnoseGrid.render('diagnoseGrid');
   queryDiagnoseForm.render('queryPanel');
   
   
});